<%@ Page language="vb" CodeFile="addVehicleStep1.aspx.vb" Inherits="addVehicleStep1_aspx_vb" %>
<%
    rowNumber = 0
    If (Request.QueryString("do")) = Nothing Then
        subDo = Request.QueryString("subDo")
        Over()
        strJS = ""
        strJS = strJS + "[""saveCountryID"", ""<1""],"
        strJS = strJS + "[""partnerName"", ""==''""],"
        strJS = strJS + "[""street"", ""==''""],"
        strJS = strJS + "[""zipCode"", ""==''""],"
        strJS = strJS + "[""city"", ""==''""]"
        checkFields()
        dbOpen()
        RecSet = Conn.Execute("Select partnerID, partnerName, countryID From tblPartner Order by partnerName")
        If Not RecSet.EOF Then
            Do Until RecSet.EOF
                partnerID = RecSet.Fields("partnerID").Value
                partnerName = RecSet.Fields("partnerName").Value
                countryID = RecSet.Fields("countryID").Value
                strSelectSubJS = strSelectSubJS + "new Array(" & partnerID & "," & countryID & ",""" & partnerName & """),"
                RecSet.MoveNext()
            Loop
        End If
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        dbOpen()
        RecSet = Conn.Execute("Select countryID From tblCountry Order by countryID")
        Do Until RecSet.EOF
            countryID = RecSet.Fields("countryID").Value
            strSelectSubJS = strSelectSubJS + "new Array(0," & countryID & ","" ------------------------------------  ""),"
            RecSet.MoveNext()
        Loop
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        strSelectSubJS = Left(strSelectSubJS, Len(strSelectSubJS) - 1)
        strSelectSubHeadline = "Select partner"
        selectSub()
        Response.Write("<table cellpadding='0' cellspacing='0' border='0' width='1000'>")
        Response.Write("<tr>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
        Response.Write("<tr><td class='headline' colspan='3'>CHOOSE A PARTNER - STEP 1 OF 7<font color='#fcbc00'>" & subDo & "</font><hr class='hrHeadline'></td></tr>")
        Response.Write("<form action='addVehicleStep1.aspx?do=selection' method='post' name='store_productsSearch'>")
        Response.Write("<tr>")
        Response.Write("<td class='formBold'>Country:</td>")
        Response.Write("<td align='right'>")
        Response.Write("<select name='countryID' id='countryID' onchange=""set_child_listbox(this, document.store_productsSearch.partnerID,Product,'Products');"">")
        Response.Write("<option value=''> Select country  ")
        dbOpen()
        RecSet = Conn.Execute("Select countryID, country From tblCountry Order By country")
        If Not RecSet.EOF Then
            Do Until RecSet.EOF
                countryID = RecSet.Fields("countryID").Value
                country = RecSet.Fields("country").Value
                Response.Write("<option value='" & countryID & "'> " & country & " ")
                RecSet.MoveNext()
            Loop
        End If
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<option value=''> -------------------------------------- ")
        Response.Write("</select>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("<tr>")
        Response.Write("<td class='formBold'>Partner:</td>")
        Response.Write("<td align='right'>")
        Response.Write("<select name='partnerID' id='partnerID' disabled>")
        Response.Write("<option value=''> Select partner ")
        Response.Write("<option value=''> -------------------------------------- ")
        Response.Write("</select>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("<tr><td align='right' colspan='2'><input type='submit' value='Step 2'></td></tr>")
        Response.Write("</form>")
        Response.Write("<tr><td colspan='3'><hr class='hrHeadline'></td></tr>")
        Response.Write("<form action='addVehicleStep1.aspx?do=save' method='post' onsubmit=""javascript:return checkFields();"">")
        Response.Write("<tr><td colspan='3'>If you can't find the specific partner above, please create a new one in the form below.</td></tr>")
        Response.Write("<tr>")
        Response.Write("<td class='formBold'>Country:</td>")
        Response.Write("<td align='right'>")
        Response.Write("<select name='saveCountryID' id='saveCountryID'>")
        Response.Write("<option value=''> Select country  ")
        dbOpen()
        RecSet = Conn.Execute("Select countryID, country From tblCountry Order By country")
        If Not RecSet.EOF Then
            Do Until RecSet.EOF
                countryID = RecSet.Fields("countryID").Value
                country = RecSet.Fields("country").Value
                Response.Write("<option value='" & countryID & "'> " & country & " ")
                RecSet.MoveNext()
            Loop
        End If
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<option value=''> -------------------------------------- ")
        Response.Write("</select>")
        Response.Write("</td>")
        Response.Write("<td><div id='error_saveCountryID' class='edit_error'>&laquo; OBS!</div></td>")
        Response.Write("</tr>")
        Response.Write("<tr><td class='formBold'>Partner:</td><td align='right'><input type='text' name='partnerName' id='partnerName' size='40' maxlength='50'></td><td><div id='error_partnerName' class='edit_error'>&laquo; OBS!</div></td></tr>")
        Response.Write("<tr><td class='formBold'>Street:</td><td align='right'><input type='text' name='street' id='street' size='40' maxlength='50'></td><td><div id='error_street' class='edit_error'>&laquo; OBS!</div></td></tr>")
        Response.Write("<tr><td class='formBold'>Zipcode:</td><td align='right'><input type='text' name='zipCode' id='zipCode' size='40' maxlength='50' onkeyup='re=/(\d*)/; re.exec(this.value); this.value=RegExp.$1;'></td><td><div id='error_zipCode' class='edit_error'>&laquo; OBS!</div></td></tr>")
        Response.Write("<tr><td class='formBold'>City:</td><td align='right'><input type='text' name='city' id='city' size='40' maxlength='50'></td><td><div id='error_city' class='edit_error'>&laquo; OBS!</div></td></tr>")
        Response.Write("<tr><td align='right' colspan='2'><input type='submit' value='Save new partner'></td></tr>")
        Response.Write("</form>")
        Response.Write("<tr><td colspan='3'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("<td width='100'></td>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
        Response.Write("<tr><td class='headline' colspan='2'>SUBSCRIPTION PROCESS<hr class='hrHeadline'></td></tr>")
        Response.Write("<tr bgcolor='#eeeeee'><td>N/A</td></tr>")
        Response.Write("<tr><td colspan='2'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("</table>")
        Under()
    ElseIf Request.QueryString("do") = "save" Then
        countryID = Request.Form("saveCountryID")
        partnerName = Request.Form("partnerName")
        street = Request.Form("street")
        zipCode = Request.Form("zipCode")
        city = Request.Form("city")
        countryID = CLng(countryID)
        If Len(partnerName) > 0 Then
            partnerName = Trim(partnerName)
            partnerName = Replace(CStr(partnerName), "'", "")
            partnerName = Replace(CStr(partnerName), """", "")
            partnerName = Replace(CStr(partnerName), "<", "")
            partnerName = Replace(CStr(partnerName), ">", "")
            partnerName = Replace(CStr(partnerName), "=", "")
        End If
        If Len(street) > 0 Then
            street = Trim(street)
            street = Replace(street, "'", "")
            street = Replace(street, """", "")
            street = Replace(street, "<", "")
            street = Replace(street, ">", "")
            street = Replace(street, "=", "")
        End If
        zipCode = CLng(zipCode)
        If Len(city) > 0 Then
            city = Trim(city)
            city = Replace(city, "'", "")
            city = Replace(city, """", "")
            city = Replace(city, "<", "")
            city = Replace(city, ">", "")
            city = Replace(city, "=", "")
        End If
        dbOpen()
        Conn.Execute("Insert Into tblPartner (countryID, partnerName, street, zipCode, city) Values(" & countryID & ",'" & partnerName & "','" & street & "'," & zipCode & ",'" & city & "')")
        dbClose()
        dbOpen()
        RecSet = Conn.Execute("SELECT MAX(partnerID) AS partnerID FROM tblPartner")
        partnerID = RecSet.Fields("partnerID").Value
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Redirect("addVehicleStep2.aspx?partnerID=" & partnerID & "")
    ElseIf Request.QueryString("do") = "selection" Then
        partnerID = Request.Form("partnerID")
        If Len(partnerID) > 0 Then
            Response.Redirect("addVehicleStep2.aspx?partnerID=" & partnerID & "")
        Else
            Response.Redirect("addVehicleStep1.aspx?subDo=%20-%20CHOOSE%20A%20PARTNER")
        End If
    End If
%>
